home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / powervww / pvitems.cpp < prev    next >
C/C++ Source or Header  |  1998-01-05  |  36KB  |  1,618 lines

  1. //  ____________________________________________________
  2. // |                                                    |
  3. // |  Project:     POWER VIEW INTERFACE                 |
  4. // |  File:        PVITEMS.CPP                          |
  5. // |  Compiler:    WPP386 (10.6)                        |
  6. // |                                                    |
  7. // |  Subject:     Base class for PV items              |
  8. // |                                                    |
  9. // |  Author:      Emil Dotchevski                      |
  10. // |____________________________________________________|
  11. //
  12. // E-mail: zajo@geocities.com
  13. // URL:    http://www.geocities.com/SiliconValley/Bay/3577
  14.  
  15. #define uses_app
  16. #define uses_colors
  17. #define uses_dc
  18. #define uses_desk
  19. #define uses_help
  20. #define uses_system
  21.  
  22. #define DECLARE_PVITEMS
  23. #include "PVuses.h"
  24. #undef DECLARE_PVITEMS
  25.  
  26. #ifndef NOHELP
  27. static uint help_context = 0;
  28. #endif
  29. static void *command_information = NULL;
  30. static uint command_size = 0;
  31.  
  32. boolean is_valid( Titem *item )
  33. {
  34.   if( ( item != NULL ) && item->valid( cmVALID ) ) return 1;
  35.   DELETE( item );
  36.   return 0;
  37. }
  38.  
  39. #ifndef NOHELP
  40. void _help( uint hlp_ctx )
  41. {
  42.   if( !help_context ) help_context = hlp_ctx;
  43. }
  44.  
  45. uint __help( void )
  46. {
  47.   uint h;
  48.  
  49.   h = help_context;
  50.   help_context = 0;
  51.   return h;
  52. }
  53. #endif
  54.  
  55. void _command_info( void *cmd_info, uint cmd_size )
  56. {
  57.   command_information = cmd_info;
  58.   command_size = cmd_size;
  59. }
  60.  
  61. Titem *message( Titem *receiver, uint command )
  62. {
  63.   if( receiver != NULL )
  64.     return receiver->handle_command( receiver, command );
  65.   else
  66.     return NULL;
  67. }
  68.  
  69. Titem *broadcast( uint command )
  70. {
  71.   return application->handle_command( NULL, command );
  72. }
  73.  
  74. Titem *modal_broadcast( uint command )
  75. {
  76.   if( modal_item != NULL )
  77.     return modal_item->handle_command( NULL, command );
  78.   else
  79.     return NULL;
  80. }
  81.  
  82. //Titem publics:
  83.  
  84. /*
  85.   Description:
  86.     Construct item with given bounds.
  87.   Entry:
  88.     _xl, _yl: item width,heigh.
  89. */
  90. Titem::Titem( int _xl, int _yl )
  91. {
  92.   flags_word = ifVISIBLE+ifSELECTABLE+ifCLOSEABLE+ifMOVABLE+ifRESIZEABLE+ifTAB_STOP;
  93.   state_word = 0;
  94.   event_mask = evCOMMAND+evKEYBOARD;
  95. #ifndef NOMOUSE
  96.   event_mask |= evMOUSE_DOWN+evMOUSE_UP+evMOUSE_DRAG;
  97. #endif
  98.   next = NULL;
  99.   owner = NULL;
  100.   last = NULL;
  101.   current = NULL;
  102.   bound_x = x = 0;
  103.   bound_y = y = 0;
  104.   bound_xl = xl = _xl;
  105.   bound_yl = yl = _yl;
  106.   curs_x = 0;
  107.   curs_y = 0;
  108.   curs_type = 0;
  109.   grow_mode = gmDONT_GROW;
  110.   drag_mode = dmDONT_DRAG;
  111. #ifndef NOHELP
  112.   help_ctx = __help();
  113. #endif
  114.   drop_id = 0;
  115.   stop_state = 0;
  116.   backgrnd_attr = 0;
  117.   backgrnd_char = ' ';
  118.   items_changed = 0;
  119.   set_state( isVALID+isACTIVE, 1 );
  120. }
  121.  
  122. /*
  123.   Description:
  124.     Dispose all subitems. Exclude self from the owner's list.
  125. */
  126. Titem::~Titem( void )
  127. {
  128.   while( last != NULL )
  129.     if( last->flags( ifSTAY ) )
  130.       remove( last );
  131.     else
  132.       DELETE( last );
  133.   if( owner != NULL ) owner->remove( this );
  134.   cancel_update( this );
  135. }
  136.  
  137. /*
  138.   Description:
  139.     Returns pointer to the first (topmost) sub-item, or NULL.
  140. */
  141. Titem *Titem::first( void )
  142. {
  143.   if( last != NULL )
  144.     return last->next;
  145.   else
  146.     return NULL;
  147. }
  148.  
  149. /*
  150.   Description:
  151.     Returns pointer to the previous sub-item in the owner's list (circular),
  152.     or NULL if item has no owner;
  153. */
  154. Titem * Titem::prev( void )
  155. {
  156.   Titem *p;
  157.  
  158.   if( owner == NULL )
  159.     return NULL;
  160.   else
  161.   {
  162.     p = this;
  163.     while( p->next != this)
  164.     {
  165.       p = p->next;
  166.     }
  167.     return p;
  168.   }
  169. }
  170.  
  171. /*
  172.   Description:
  173.     Returns pointer to the next sub-item in the owner's list (linear),
  174.     or NULL if it is the last item, or has no owner;
  175. */
  176. Titem * Titem::nextl( void )
  177. {
  178.   if( ( owner == NULL ) || ( owner->last == this ) )
  179.     return NULL;
  180.   else
  181.     return next;
  182. }
  183.  
  184. /*
  185.   Description:
  186.     Returns pointer to the previous sub-item in the owner's list (linear),
  187.     or NULL if it is the first item, or has no owner;
  188. */
  189. Titem * Titem::prevl( void )
  190. {
  191.   if( ( owner == NULL ) || ( owner->first() == this ) )
  192.     return NULL;
  193.   else
  194.     return prev();
  195. }
  196.  
  197. /*
  198.   Description:
  199.     Set or clear flags_word bits depending on 'enable'. Handle some special
  200.     cases. Can be overriden to handle more special cases.
  201.   Entry:
  202.     _flags_word: requested bit mask;
  203.     enable:      1 - set bits, 0 - clear.
  204. */
  205. void Titem::set_flags( uint _flags_word, boolean enable )
  206. {
  207.   uint f;
  208.  
  209.   if( ( _flags_word & ifSELECTABLE ) && !enable && state( isSELECTED ) )
  210.   {
  211.     set_state( isSELECTED, 0 );
  212.     if( state( isSELECTED ) ) _flags_word &= ~ifSELECTABLE;
  213.   }
  214.   f = flags_word;
  215.   if( enable )
  216.     flags_word |= _flags_word;
  217.   else
  218.     flags_word &= ~_flags_word;
  219.   if( ( f != flags_word ) && ( _flags_word & ifVISIBLE ) ) redraw();
  220. }
  221.  
  222. /*
  223.   Description:
  224.     Set or clear state bits depending on 'enable'. Handle some special
  225.     cases. Can be overriden to handle more special cases.
  226.   Entry:
  227.     _state_word: requested bit mask;
  228.     enable:      1 - set bits, 0 - clear.
  229. */
  230. void Titem::set_state( uint _state_word, boolean enable )
  231. {
  232.   uint s, ns;
  233.   boolean f;
  234.   Titem *p;
  235.  
  236.   if( enable )
  237.   {
  238.     if( ( _state_word & isACTIVE ) &&
  239.           flags( ifSELECTABLE ) && !state( isSELECTED ) )
  240.       _state_word &= ~isACTIVE;
  241.     if( ( _state_word & isACCESSABLE ) && !event_mask )
  242.       _state_word &= ~isACCESSABLE;
  243.     if( ( _state_word & isALIVE ) && ( !flags( ifVISIBLE ) || state( isHIDDEN ) ) )
  244.       _state_word &= ~isALIVE;
  245.     if( ( _state_word & isSELECTED ) &&
  246.         ( !flags(ifSELECTABLE) || owner==NULL ||
  247.           ( ( ( p = owner->current ) != NULL ) &&
  248.             ( p->set_state( isSELECTED, 0 ),
  249.               p->state( isSELECTED )
  250.             )
  251.           )
  252.         )
  253.       )
  254.       _state_word &= ~isSELECTED;
  255.   }
  256.   else
  257.     if( ( _state_word & isSELECTED ) && state( isFOCUSED ) && !release_focus() )
  258.       _state_word &= ~isSELECTED;
  259.   if( enable ) ns = state_word | _state_word; else ns = state_word & ~_state_word;
  260.   if( state_word == ns ) return;
  261.   s = _state_word & ( isACTIVE+isALIVE+isDISABLED+isACCESSABLE );
  262.   if( s )
  263.     for( p=first(); p!=NULL; p=p->nextl() )
  264.       p->set_state( s, enable );
  265.   f = ( ( _state_word & ( isFOCUSED+isSELECTED+isDISABLED+isHIDDEN ) ) != 0 );
  266.   if( f ) redraw();
  267.   s = state_word; state_word = ns;
  268.   if( ( state_word & isHIDDEN ) != ( s & isHIDDEN ) )
  269.   {
  270.     set_state( isALIVE, !enable && owner && owner->state( isALIVE ) );
  271.     if( owner != NULL )
  272.       if( enable )
  273.         req_update( owner );
  274.       else
  275.         owner->update_bounds( this );
  276.   }
  277.   if( ( state_word & isDISABLED ) != ( s & isDISABLED ) )
  278.     set_state( isACTIVE, !enable );
  279.   if( ( state_word & isSELECTED ) != ( s & isSELECTED ) )
  280.   {
  281.     set_state( isACTIVE, enable );
  282.     if( owner != NULL )
  283.       if( enable )
  284.       {
  285.         owner->current = this;
  286.         p = owner;
  287.         while( ( p != modal_item ) && ( p->owner != NULL ) && ( p->owner->current == p ) )
  288.           p = p->owner;
  289.         if( p == modal_item ) set_state( isFOCUSED, 1 );
  290.       }
  291.       else
  292.       {
  293.         owner->current = NULL;
  294.         set_state( isFOCUSED, 0 );
  295.       }
  296.   }
  297.   if( ( state_word & isFOCUSED ) != ( s & isFOCUSED ) )
  298.   {
  299.     if( enable ) get_focused();
  300.     if( current != NULL ) current->set_state( isFOCUSED, enable );
  301.   }
  302.   if( f ) redraw();
  303.   if( ( state_word & isMODAL ) != ( s & isMODAL ) )
  304.   {
  305.     set_state( isACCESSABLE, enable );
  306.     if( enable ) set_state( isACTIVE, 1 );
  307.   }
  308.   if( ( _state_word & isON_TOP ) && owner )
  309.     if( enable )
  310.       owner->pop_item( this );
  311.     else
  312.       owner->do_pop_top_items( owner->last );
  313. }
  314.  
  315. /*
  316.   Description:
  317.     Test state of the item's owner just before desktop or application.
  318.     Usually used to determine is the window that (indirectly) owns the
  319.     item active, selected, and so on.
  320. */
  321. boolean Titem::window_state( uint _state_word )
  322. {
  323.   Titem *p;
  324.  
  325.   p = this;
  326.   while( p->owner != NULL )
  327.   {
  328.     if( ( p->owner == desktop ) || ( p->owner == application ) )
  329.       return p->state( _state_word );
  330.     p = p->ow